package com.lingshi.shopping_manager_api.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import com.lingshi.shopping_manager_api.security.CheckLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.rmi.registry.Registry;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /*
    自定义拦截器
    */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //注册登录检查拦截器，检查是否登录
        registry.addInterceptor(new CheckLoginInterceptor())
                .addPathPatterns("/**")//所有请求都拦截
                .excludePathPatterns("/admin/login");   // 放行/admin/模块下的所有资源（如登录，注册，找回密码等不能拦截）

        //注册授权拦截器
        // 注册 Sa-Token 拦截器，打开注解式鉴权功能
        registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**");
        }

    }
